package util;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.UUID;

public class FileUtil {

    public static String getStringFromInputStream(InputStream inputStream) throws IOException {
        InputStreamReader inputStreamReader = new InputStreamReader(inputStream);
        BufferedReader bufferedReader = new BufferedReader(inputStreamReader);
        String buffer = "";
        StringBuffer stringBuffer = new StringBuffer();
        while((buffer=bufferedReader.readLine())!=null){
            stringBuffer.append(buffer);

        }
        return stringBuffer.toString();
    }





    public static String getRandomFileName(String fileName){
        int index = fileName.lastIndexOf(".");
        String suffix = fileName.substring(index+1);
        return fileName.substring(0,index) + "_"+ UUID.randomUUID()+"."+suffix;

    }
}
